package reproductores;

import java.io.IOException;

public class VLC {
	
	public static void encolar(boolean solamenteEncolar, boolean unSoloTema, String url, String primerTema) {
		
		if (solamenteEncolar) {
			
			if (unSoloTema)
				url = "\"" + url + "\"";

			String[] commandLin = new String[]{"bash", "-c", "vlc --one-instance --playlist-enqueue " + url};
					
			try {
				Runtime.getRuntime().exec(commandLin);
			} catch (IOException e) {
				e.printStackTrace();
			} 
			
		}
		else {
				
			if (unSoloTema) {
					
				String[] commandLin = new String[]{"bash", "-c", "vlc --one-instance \"" + url + "\""};
				
				try {
					//System.out.println(commandLin[0] + " " + commandLin[1] + " " + commandLin[2]);//+ " " + commandLin[3]+ " " + commandLin[4]);
					@SuppressWarnings("unused")
					Process procesoLin;
					procesoLin = Runtime.getRuntime().exec(commandLin, null, null);
					//System.out.println(commandLin[0] + " " + commandLin[1] + " " + commandLin[2]);

				}
				catch (Exception e) {
					e.printStackTrace();
				}
			}
			else {
				//String restoTemas[] = url.split(primerTema);
				String[] commandLin = {"bash", "-c", "vlc --one-instance " + url  /*+ " --playlist-enqueue " + restoTemas[1]*/};
				System.out.println(commandLin[0] + " " + commandLin[1]  + " " + commandLin[2]);
				try {
					Runtime.getRuntime().exec(commandLin);
				} catch (IOException e) {
					e.printStackTrace();
				} 
					
				//System.out.println(url);
				/*String restoTemas[] = url.split(primerTema);
				//System.out.println(primerTema);
				if (restoTemas.length > 1) {
					commandLin = new String[]{"bash", "-c", "vlc --one-instance --playlist-enqueue " + restoTemas[1]};
					System.out.println(commandLin[0] + " " + commandLin[1]  + " " + commandLin[2]);
					//System.out.println(mocp[0] + " " + mocp[1] + " " + mocp[2]);
					try {
						Runtime.getRuntime().exec(commandLin);
					} catch (IOException e) {
						e.printStackTrace();
					} 
				}*/
			}
		}
	}
	
	public static void activarShuffle() {
		String[] mocp = {"bash", "-c", "vlc --one-instance --random "};
		try {
			Runtime.getRuntime().exec(mocp);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void desactivarShuffle() {
		String[] mocp = {"bash", "-c", "vlc --one-instance --no-random "};
		try {
			Runtime.getRuntime().exec(mocp);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
